<?php

namespace app\admin\controller;
use app\admin\model\Api;
use app\admin\model\ApiParam;
use app\admin\model\ApiType;

class ApiParamController extends BaseController
{
    public function index()
    {
        $ApiType = new ApiType();
        $ApiType = $ApiType->select();
        $this->assign('ApiType',$ApiType);
        return $this->fetch();
    }
    /**
     * author：廖桂钦
     * eamil : artistCode@163.com
     * create time :2020/4/8
     * description[读取api 列表]
     */
    public function read(){
        $ApiParam =  new ApiParam();
        if (isset($_GET['api_id'])){
            $ApiParam =  $ApiParam->where('api_id',input('get.api_id'));
        }
        $count = $ApiParam->count();

        $page =  $this->request->param('page');
        $limit =  $this->request->param('limit');
        $list = $ApiParam->page($page,$limit)->select();

        return ['code' => 0, 'msg' => '数据返回成功', 'data' => $list, 'count' => $count];
    }

    /**
     * author：廖桂钦
     * eamil : artistCode@163.com
     * create time :2020/4/8
     */
    public function add(){

        $ApiParam =  new ApiParam();
        $post_data= input('post.');

        $data= $ApiParam->save($post_data);
            if ($data) {
                return json(['code' => 0, 'msg' => '添加成功']);
            } else {
                return json(['code' => 500, 'msg' => '添加失败']);
            }

    }

    public function upd()
    {
        $ApiParam= (new ApiParam());
        $post_data = input('post.');
        $post_data['is_param'] = isset( $post_data['is_param']) ?   $post_data['is_param'] : 0;

            $ApiParam->isUpdate(true)->save($post_data);
        if ($ApiParam) {
            return json(['code' => 0, 'msg' => '更新成功']);
        } else {
            return json(['code' => 500, 'msg' => '更新失败']);
        }
    }
    public function  del(){
        $result =ApiParam::get(input('post.'))->delete();
        if($result){
            return json(['code'=>0,'msg'=>'删除成功']);
        }else{
            return json(['code'=>500,'msg'=>'删除失败']);
        }
    }

}
